package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"runtime"
	"trade/logger"
)

func NewConfig(configFilePath string) (*Config, error) {

	yamlFile, err := ioutil.ReadFile(configFilePath)
	if err != nil {
		logger.Log.Error(err.Error())
		return nil, err
	}
	conf := new(Config)
	err = yaml.Unmarshal(yamlFile, conf)
	if err != nil {
		logger.Log.Error(err.Error())
		return nil, err
	}
	logger.Log.Info("config loaded ", configFilePath)
	return conf, nil
}
func GetCurrentFilepath() (filename string) {
	_, filename, _, _ = runtime.Caller(0)
	return filename
}
